package edu.jptest.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class GetDataBaseConnection {

	private Connection conn = null;

	public GetDataBaseConnection() {
		try {
			Context ctx = new InitialContext();
			DataSource dSource = (DataSource) ctx
					.lookup("java:comp/env/jdbc/jptest");
			if (null != dSource) {
				conn = dSource.getConnection();
			} else {
				System.out.println("连接数据源出错！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("连接数据库出错！");
		}
	}

	public Connection getConnection() {
		return this.conn;
	}

}